package com.basic.modules.ykf.controller;

import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.basic.common.annotation.StringTrim;
import com.basic.common.exception.RRException;
import com.basic.common.utils.ParamsModel;
import com.basic.common.validator.ValidatorUtils;
import com.basic.modules.sys.controller.AbstractController;
import com.basic.modules.sys.entity.SysUserEntity;
import com.basic.modules.ykf.entity.*;
import com.basic.modules.ykf.model.CommissionModel;
import com.basic.modules.ykf.model.CustomerStatisticsReq;
import com.basic.modules.ykf.model.CustomerStatisticsResp;
import com.basic.modules.ykf.service.YkfCustomerShopHistoryService;
import com.basic.modules.ykf.service.YkfCustomerShopService;
import com.basic.modules.ykf.service.YkfShopChangeRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import com.basic.modules.ykf.service.YkfCustomerService;
import com.basic.common.utils.PageUtils;
import com.basic.common.utils.R;

/**
 * 客户管理
 *
 * @author maoheng
 * @email 15738859597@163.com
 * @date 2024-04-06 18:40:44
 */
@RestController
@RequestMapping("ykf/customer")
public class YkfCustomerController extends AbstractController {

    @Autowired
    private YkfCustomerService ykfCustomerService;

    @Autowired
    private YkfCustomerShopService ykfCustomerShopService;

    @Autowired
    private YkfCustomerShopHistoryService historyService;

    @Autowired
    private YkfShopChangeRecordService changeRecordService;

    /**
     * 列表-分页
     */
    @StringTrim
    @PostMapping("/page")
    public R list(@RequestBody ParamsModel<YkfCustomerShopEntity> params) {
        params.getCondition().setCooperateStatus(1);
        PageUtils page = ykfCustomerService.queryPage(params);
        return R.ok(page);
    }

    /**
     * 列表-分页
     */
    @StringTrim
    @PostMapping("/customerLvlInfo")
    public R customerLvlInfo(@RequestBody YkfCustomerShopEntity params) {
        if (ObjectUtil.isNotEmpty(params) && ObjectUtil.isNotEmpty(params.getShopId())) {
            Map<String, Object> map = ykfCustomerService.customerLvlInfo(params);
            return R.ok(map);
        } else {
            throw new RRException("参数缺失");
        }
    }

    /**
     * 查询列表-分页
     */
    @StringTrim
    @PostMapping("/selectPage")
    public R selectPage(@RequestBody ParamsModel<YkfCustomerEntity> params) {
        PageUtils page = ykfCustomerService.selectPage(params);
        return R.ok(page);
    }

    /**
     * 店铺效益
     */
    @StringTrim
    @PostMapping("/shopBenefitPage")
    public R shopBenefitPage(@RequestBody ParamsModel<YkfCustomerShopEntity> params) {
        params.getCondition().setCooperateStatus(1);
        PageUtils page = ykfCustomerService.shopBenefitPage(params);
        return R.ok(page);
    }

    /**
     * 店铺效益详情
     */
    @StringTrim
    @PostMapping("/shopBenefitDetail")
    public R shopBenefitDetail(@RequestBody YkfCustomerShopEntity params) {
        if (ObjectUtil.isEmpty(params) || StrUtil.isBlank(params.getMonth()) || ObjectUtil.isEmpty(params.getShopId())) {
            throw new RRException("参数缺失");
        }
        params.setCooperateStatus(1);
        List<CommissionModel> list = ykfCustomerService.shopBenefitDetail(params);
        if (ObjectUtil.isNotEmpty(list)) {
            for (CommissionModel model : list) {
                model.setMonth(params.getMonth());
            }
        }
        return R.ok(list);
    }

    /**
     * 停止合作的列表-分页
     */
    @StringTrim
    @PostMapping("/stopPage")
    public R stopPage(@RequestBody ParamsModel<YkfCustomerShopEntity> params) {
        params.getCondition().setCooperateStatus(0);
        PageUtils page = ykfCustomerService.queryStopPage(params);
        return R.ok(page);
    }

    /**
     * 历史客户信息,其实就是停止合作的店铺加了些字段而已
     */
    @PostMapping("/getHistoricalShop")
    public R getHistoricalShop(@RequestBody ParamsModel<YkfCustomerShopEntity> params){
        params.getCondition().setCooperateStatus(0);
        PageUtils page = ykfCustomerService.getHistoricalShop(params);
        return R.ok(page);
    }

    /**
     * 停止合作的列表-分页
     */
    @PostMapping("/updateStopShopInfo")
    public R updateStopShopInfo(@RequestBody YkfCustomerShopEntity shop) {
        if (ObjectUtil.isNotEmpty(shop) && ObjectUtil.isNotEmpty(shop.getShopId())) {
            UpdateWrapper<YkfCustomerShopEntity> updateWrapper = new UpdateWrapper<>();
            updateWrapper.lambda().eq(YkfCustomerShopEntity::getShopId, shop.getShopId())
                    .set(YkfCustomerShopEntity::getRecoveryResult, shop.getRecoveryResult())
                    .set(YkfCustomerShopEntity::getStopUserDept, shop.getStopUserDept())
                    .set(YkfCustomerShopEntity::getStopUserDeptName, shop.getStopUserDeptName())
                    .set(YkfCustomerShopEntity::getStopUserId, shop.getStopUserId())
                    .set(YkfCustomerShopEntity::getStopUser, shop.getStopUser())
                    .set(YkfCustomerShopEntity::getRealReason, shop.getRealReason())
                    .set(YkfCustomerShopEntity::getJudgeReason, shop.getJudgeReason());
            ykfCustomerShopService.update(updateWrapper);
        }
        return R.ok();
    }


    /**
     * 信息
     */
    @PostMapping("/info")
    public R info(@RequestBody YkfCustomerEntity param) {
        if (ObjectUtil.isEmpty(param) || ObjectUtil.isEmpty(param.getCustomerId())) {
            throw new RRException("参数缺失");
        }
        YkfCustomerEntity customerEntity = ykfCustomerService.getById(param.getCustomerId());
        if (ObjectUtil.isNotEmpty(customerEntity)) {
            QueryWrapper<YkfCustomerShopEntity> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().eq(YkfCustomerShopEntity::getCustomerId, customerEntity.getCustomerId());
            List<YkfCustomerShopEntity> list = ykfCustomerShopService.list(queryWrapper);
            customerEntity.setShopList(list);
        }
        return R.ok(customerEntity);
    }


    /**
     * 收费分组信息
     */
    @PostMapping("/groupShopInfo")
    public R groupShopInfo(@RequestBody YkfCustomerEntity param) {
        if (ObjectUtil.isEmpty(param) || ObjectUtil.isEmpty(param.getCustomerId())) {
            throw new RRException("参数缺失");
        }
        Map<String, List<YkfCustomerShopEntity>> map = ykfCustomerService.groupShopInfo(param);
        return R.ok(map);
    }

    /**
     * 已有分组
     */
    @PostMapping("/groupList")
    public R groupList(@RequestBody YkfCustomerEntity param) {
        if (ObjectUtil.isEmpty(param) || ObjectUtil.isEmpty(param.getCustomerId())) {
            throw new RRException("参数缺失");
        }
        List<String> groupList = ykfCustomerService.groupList(param);
        return R.ok(groupList);
    }

    /**
     * 分组
     */
    @PostMapping("/dispatchGroup")
    public R groupInfo(@RequestBody YkfCustomerEntity param) {
        if (ObjectUtil.isEmpty(param) || ObjectUtil.isEmpty(param.getCustomerId()) || ObjectUtil.isEmpty(param.getShopIds()) || StrUtil.isBlank(param.getMergeGroup())) {
            throw new RRException("参数缺失");
        }
        ykfCustomerService.dispatchGroup(param);
        return R.ok();
    }

    /**
     * 批量修改店铺对接人
     */
    @PostMapping("/batchUpdateStoreLiaison")
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public R batchUpdateStoreLiaison(@RequestBody YkfCustomerEntity param) {
//        if (StrUtil.isNotBlank(param.getStoreLiaison()) && ObjectUtil.isNotEmpty(param.getShopIds())) {
//            UpdateWrapper<YkfCustomerShopEntity> updateWrapper = new UpdateWrapper<>();
//            updateWrapper.lambda().in(YkfCustomerShopEntity::getShopId, param.getShopIds())
//                    .set(YkfCustomerShopEntity::getStoreLiaison, param.getStoreLiaison());
//            ykfCustomerShopService.update(updateWrapper);
//        }
        if (StrUtil.isNotBlank(param.getStoreLiaison()) && StrUtil.isNotBlank(param.getOldStoreLiaison())) {
            UpdateWrapper<YkfCustomerShopEntity> updateWrapper = new UpdateWrapper<>();
            updateWrapper.lambda().eq(YkfCustomerShopEntity::getStoreLiaison, param.getOldStoreLiaison())
                    .set(YkfCustomerShopEntity::getStoreLiaison, param.getStoreLiaison());
            ykfCustomerShopService.update(updateWrapper);
        }
        return R.ok();
    }

    /**
     * 保存 TODO 加锁
     */
    @PostMapping("/save")
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public R save(@RequestBody YkfCustomerEntity ykfCustomer) {
        ValidatorUtils.validateEntity(ykfCustomer);
        //校验
        validCustomer(ykfCustomer);
        //生成客户编号
        QueryWrapper<YkfCustomerEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().like(YkfCustomerEntity::getCustomerNo, "KH")
                .orderByDesc(YkfCustomerEntity::getCustomerNo);
        queryWrapper.last("limit 1");
        YkfCustomerEntity one = ykfCustomerService.getOne(queryWrapper);
        if (ObjectUtil.isNotEmpty(one)) {
            String customerNo = one.getCustomerNo();
            if (StrUtil.isNotBlank(customerNo)) {
                try {
                    BigDecimal kh = new BigDecimal(StrUtil.replace(customerNo, "KH", ""));
                    String format = String.format("%05d", (kh.add(BigDecimal.ONE)).intValue());
                    ykfCustomer.setCustomerNo("KH" + format);
                } catch (Exception e) {
                    ykfCustomer.setCustomerNo("KH00001");
                }
            }
        } else {
            ykfCustomer.setCustomerNo("KH00001");
        }
        ykfCustomerService.save(ykfCustomer);
        //保存店铺信息
        if (ObjectUtil.isNotEmpty(ykfCustomer.getShopList())) {
            DateTime date = DateUtil.date();
            SysUserEntity user = getUser();
            List<YkfShopChangeRecordEntity> recordList = new ArrayList<>();
            for (int i = 0; i < ykfCustomer.getShopList().size(); i++) {
                YkfCustomerShopEntity item = ykfCustomer.getShopList().get(i);
                item.setCustomerId(ykfCustomer.getCustomerId());
                //生成店铺编号
                item.setShopNo("SHOP" + String.format("%02d", i + 1));
                if (ObjectUtil.isEmpty(item.getShopId())) {
                    item.setFirstStartDate(item.getStartDate());
                }
                if (item.getCooperateStatus() == 0) {
                    item.setStopCooperateDate(date);
                    item.setStopUser(user.getName());
                    item.setStopUserDept(user.getDeptName());
                }
            }
            ykfCustomerShopService.saveBatch(ykfCustomer.getShopList());
            for (YkfCustomerShopEntity shopEntity : ykfCustomer.getShopList()) {
                //保存记录
                YkfShopChangeRecordEntity record = new YkfShopChangeRecordEntity();
                BeanUtil.copyProperties(shopEntity, record);
                record.setUpdTime(DateUtil.date());
                record.setUpdUserId(getUserId());
                record.setUpdUserName(getUser().getName());
                recordList.add(record);
            }
            changeRecordService.saveBatch(recordList);
            String name = getUser().getName();
            List<YkfCustomerShopHistoryEntity> historyList = new ArrayList<>();
            for (YkfCustomerShopEntity item : ykfCustomer.getShopList()) {
                //保存店铺历史记录
                YkfCustomerShopHistoryEntity history = new YkfCustomerShopHistoryEntity();
                BeanUtil.copyProperties(item, history);
                history.setOperator(name);
                historyList.add(history);
            }
            historyService.saveBatch(historyList);
        }
        return R.ok();
    }

    private void validCustomer(YkfCustomerEntity ykfCustomer) {
//        QueryWrapper<YkfCustomerEntity> queryWrapper = new QueryWrapper<>();
//        queryWrapper.lambda().eq(YkfCustomerEntity::getCustomerNo, ykfCustomer.getCustomerNo());
//        if (ObjectUtil.isNotEmpty(ykfCustomer.getCustomerId())) {
//            queryWrapper.lambda().ne(YkfCustomerEntity::getCustomerId, ykfCustomer.getCustomerId());
//        }
//        if (ykfCustomerService.count(queryWrapper) > 0) {
//            throw new RRException("客户编号" + ykfCustomer.getCustomerNo() + "已存在，请检查");
//        }
//        if (ObjectUtil.isNotEmpty(ykfCustomer.getShopList())) {
//            for (YkfCustomerShopEntity item : ykfCustomer.getShopList()) {
//                QueryWrapper<YkfCustomerShopEntity> shopQueryWrapper = new QueryWrapper<>();
//                shopQueryWrapper.lambda().eq(YkfCustomerShopEntity::getShopNo, item.getShopNo());
//
//            }
//        }
        QueryWrapper<YkfCustomerEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(YkfCustomerEntity::getCustomerName, ykfCustomer.getCustomerName());
        if (ObjectUtil.isNotEmpty(ykfCustomer.getCustomerId())) {
            queryWrapper.lambda().ne(YkfCustomerEntity::getCustomerId, ykfCustomer.getCustomerId());
        }
        if (ykfCustomerService.count(queryWrapper) > 0) {
            throw new RRException("客户名称" + ykfCustomer.getCustomerName() + "已存在，请检查");
        }
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public R update(@RequestBody YkfCustomerEntity ykfCustomer) {
        ValidatorUtils.validateEntity(ykfCustomer);
        //校验
        validCustomer(ykfCustomer);
        ykfCustomerService.updateById(ykfCustomer);
        //修改店铺信息
        if (ObjectUtil.isNotEmpty(ykfCustomer.getShopList())) {
            DateTime date = DateUtil.date();
            SysUserEntity user = getUser();
            for (int i = 0; i < ykfCustomer.getShopList().size(); i++) {
                YkfCustomerShopEntity item = ykfCustomer.getShopList().get(i);
                item.setCustomerId(ykfCustomer.getCustomerId());
                //生成店铺编号
                item.setShopNo("SHOP" + String.format("%02d", i + 1));
                if (ObjectUtil.isEmpty(item.getShopId())) {
                    item.setFirstStartDate(item.getStartDate());
                    if (item.getCooperateStatus() == 0) {
                        item.setStopCooperateDate(date);
                        item.setStopUser(user.getName());
                        item.setStopUserDept(user.getDeptName());
                    }
                }
            }
            ykfCustomerShopService.saveOrUpdateBatch(ykfCustomer.getShopList());
            //保存历史记录
            String name = getUser().getName();
            List<YkfCustomerShopHistoryEntity> historyList = new ArrayList<>();
            for (YkfCustomerShopEntity item : ykfCustomer.getShopList()) {
                //保存店铺历史记录
                YkfCustomerShopHistoryEntity history = new YkfCustomerShopHistoryEntity();
                BeanUtil.copyProperties(item, history);
                history.setOperator(name);
                historyList.add(history);
            }
            historyService.saveBatch(historyList);
        }
        //修改店铺里的客户名称
        //修改子账号里的客户名称

        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public R delete(@RequestBody Long[] customerIds) {
        QueryWrapper<YkfCustomerShopEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().in(YkfCustomerShopEntity::getCustomerId, Arrays.asList(customerIds));
        if (ykfCustomerShopService.count(queryWrapper) > 0) {
            throw new RRException("店铺有数据的客户不能删除");
        }
        ykfCustomerService.removeByIds(Arrays.asList(customerIds));
//        ykfCustomerShopService.remove(queryWrapper);
        return R.ok();
    }

    /**
     * 新增客户统计
     */
    @PostMapping("/addCustomerStatistics")
    public R addCustomerStatistics() {
        //查询所有店铺
        List<YkfCustomerShopEntity> list = ykfCustomerShopService.list();
        List<Map<String, Integer>> addList = new ArrayList<>();
        if (ObjectUtil.isNotEmpty(list)) {
            Map<String, List<String>> collect = list.stream().map(o -> DateUtil.format(o.getCreateTime(), "yyyy-MM")).collect(Collectors.groupingBy(o -> o));
            for (String key : collect.keySet()) {
                Map<String, Integer> map = new HashMap<>();
                map.put(key, collect.get(key).size());
                addList.add(map);
            }
        }
        return R.ok(addList);
    }

    /**
     * 流失客户统计
     */
    @PostMapping("/lossCustomerStatistics")
    public R lossCustomerStatistics() {
        QueryWrapper<YkfCustomerShopEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(YkfCustomerShopEntity::getCooperateStatus, 0);
        List<YkfCustomerShopEntity> list = ykfCustomerShopService.list(queryWrapper);
        List<Map<String, Integer>> lossList = new ArrayList<>();
        if (ObjectUtil.isNotEmpty(list)) {
            Map<String, List<String>> collect = list.stream().filter(o -> ObjectUtil.isNotEmpty(o.getStopCooperateDate())).map(o -> DateUtil.format(o.getStopCooperateDate(), "yyyy-MM")).collect(Collectors.groupingBy(o -> o));
            for (String key : collect.keySet()) {
                Map<String, Integer> map = new HashMap<>();
                map.put(key, collect.get(key).size());
                lossList.add(map);
            }
        }
        return R.ok(lossList);
    }

    /**
     * 客户统计
     */
    @PostMapping("/customerStatistics")
    public R customerStatistics(@RequestBody CustomerStatisticsReq param) {
        //查询所有店铺
        List<YkfCustomerShopEntity> list = ykfCustomerShopService.list();
        //按平台分组
        CustomerStatisticsResp resp = new CustomerStatisticsResp();
        if (ObjectUtil.isNotEmpty(list)) {
            resp.setSumCustomerCount(list.size());
            List<Map<String, Integer>> platformList = new ArrayList<>();
            Map<String, List<YkfCustomerShopEntity>> collect = list.stream().collect(Collectors.groupingBy(YkfCustomerShopEntity::getPlatformNo));
            for (String key : collect.keySet()) {
                List<YkfCustomerShopEntity> shopList = collect.get(key);
                Map<String, Integer> map = new HashMap<>();
                if (StrUtil.isNotBlank(shopList.get(0).getPlatformName())) {
                    map.put(shopList.get(0).getPlatformName(), shopList.size());
                    platformList.add(map);
                }
            }
            resp.setPlatformList(platformList);
        }
        List<Map<String, Integer>> addList = new ArrayList<>();
        //查询新增客户统计-按createTime
        if (ObjectUtil.isEmpty(param.getAddCustomerDateEnd()) || ObjectUtil.isEmpty(param.getAddCustomerDateStart())) {
            DateTime date = DateUtil.date();
            param.setAddCustomerDateEnd(date);
            DateTime date1 = DateUtil.offsetMonth(date, -11);
            param.setAddCustomerDateStart(date1);
        }

        //从开始时间到结束时间分月查询
        long ll = DateUtil.betweenMonth(param.getAddCustomerDateStart(), param.getAddCustomerDateEnd(), true);
        for (long l = 0; l < ll + 1; l++) {
            String startDate = "";
            String endDate = "";
            if (l == 0) {
                startDate = DateUtil.formatDate(param.getAddCustomerDateStart());
                if (ll == 0) {
                    endDate = DateUtil.formatDate(param.getAddCustomerDateEnd());
                } else {
                    //取当前月份最后一天
                    endDate = DateUtil.formatDate(DateUtil.endOfMonth(param.getAddCustomerDateStart()));
                }
            } else if (l == ll) {
                endDate = DateUtil.formatDate(param.getAddCustomerDateEnd());
                startDate = DateUtil.formatDate(DateUtil.beginOfMonth(param.getAddCustomerDateEnd()));
            } else {
                DateTime dateTime = DateUtil.offsetMonth(param.getAddCustomerDateStart(), (int) l);
                startDate = DateUtil.formatDate(DateUtil.beginOfMonth(dateTime));
                endDate = DateUtil.formatDate(DateUtil.endOfMonth(dateTime));
            }
            int countAdd = countAdd(list, startDate, endDate);
            Map<String, Integer> map = new HashMap<>();
            map.put(DateUtil.format(DateUtil.parseDate(startDate), "yyyy-MM"), countAdd);
            addList.add(map);
        }
        resp.setAddList(addList);

        List<Map<String, Integer>> lossList = new ArrayList<>();
        if (ObjectUtil.isEmpty(param.getLossCustomerDateEnd()) || ObjectUtil.isEmpty(param.getLossCustomerDateStart())) {
            DateTime date = DateUtil.date();
            param.setLossCustomerDateEnd(date);
            DateTime date1 = DateUtil.offsetMonth(date, -11);
            param.setLossCustomerDateStart(date1);
        }
        //从开始时间到结束时间分月查询
        long lossL = DateUtil.betweenMonth(param.getLossCustomerDateStart(), param.getLossCustomerDateEnd(), true);
        for (long l = 0; l < lossL + 1; l++) {
            String startDate = "";
            String endDate = "";
            if (l == 0) {
                startDate = DateUtil.formatDate(param.getAddCustomerDateStart());
                if (lossL == 0) {
                    endDate = DateUtil.formatDate(param.getAddCustomerDateEnd());
                } else {
                    //取当前月份最后一天
                    endDate = DateUtil.formatDate(DateUtil.endOfMonth(param.getAddCustomerDateStart()));
                }
            } else if (l == lossL) {
                endDate = DateUtil.formatDate(param.getAddCustomerDateEnd());
                startDate = DateUtil.formatDate(DateUtil.beginOfMonth(param.getAddCustomerDateEnd()));
            } else {
                DateTime dateTime = DateUtil.offsetMonth(param.getAddCustomerDateStart(), (int) l);
                startDate = DateUtil.formatDate(DateUtil.beginOfMonth(dateTime));
                endDate = DateUtil.formatDate(DateUtil.endOfMonth(dateTime));
            }
            int countLoss = countLoss(list, startDate, endDate);
            Map<String, Integer> map = new HashMap<>();
            map.put(DateUtil.format(DateUtil.parseDate(startDate), "yyyy-MM"), countLoss);
            lossList.add(map);
        }
        resp.setLossList(lossList);

        return R.ok(resp);
    }

    private int countAdd(List<YkfCustomerShopEntity> list, String startDate, String endDate) {
        long count = list.stream().filter(o ->
                ObjectUtil.isNotEmpty(o.getCreateTime())
                        && DateUtil.formatDate(o.getCreateTime()).compareTo(startDate) >= 0
                        && DateUtil.formatDate(o.getCreateTime()).compareTo(endDate) <= 0).count();
        return (int) count;
    }

    private int countLoss(List<YkfCustomerShopEntity> list, String startDate, String endDate) {
        long count = list.stream().filter(o ->
                (ObjectUtil.isEmpty(o.getCooperateStatus()) || o.getCooperateStatus() == 0)
                        && DateUtil.formatDate(o.getStopCooperateDate()).compareTo(startDate) >= 0
                        && DateUtil.formatDate(o.getStopCooperateDate()).compareTo(endDate) <= 0).count();
        return (int) count;
    }

    public static void main(String[] args) {
        DateTime dateTime1 = DateUtil.parseDate("2024-01-23");
        DateTime dateTime2 = DateUtil.parseDate("2024-01-25");
        long l = DateUtil.betweenMonth(dateTime1, dateTime2, true);
        System.out.println(l);
    }

}
